<template>
  <div>
    <FilterTable
      ref="firsttable"
      :fetchapi="fetchApi1"
      :columns="columns1"
      :params="fetchParams1"
      :datakey="'rows'"
      :isSelectColumn="false"
      :onColumnsChange="columns1 => (this.columns1 = columns1)"
      height="auto"
      columnsRef="zjwxlssettlementTables1"
    ></FilterTable>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import dictCode from '@/utils/dictCode';
import { searchRoleByCode, searchRoleByCodes } from '@/api/common/empSelect/index';
import exchanging from './exchanging.vue';
import { getSeries } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getWXXM, getWXCL, getXSCL, getFJXM } from '@/api/repair/business/customer/history';
import { queryRepairLabour, queryRepairPart, querySellMaterial, queryChargeDifferentiationList } from '@/api/repair/repairReception/repairBusinessManger';
import { getSfqfSelect, getGongzSelect, getSflbList, getWxlxSelect, getRepairTypeData, getZdjsSelect } from '@/api/repair/repairReception/customer';
export default {
  name: 'zjsettlementTables',
  components: {
    exchanging
  },
  mixins: [dictionary],
  props: ['getdata'],
  data() {
    this.firsttable = null;
    return {
      fetchParams1: { RO_NO: this.getdata.RO_NO },
      columns1: this.createTable1(),
      fetchApi1: getWXXM,
      exchangingVisible: false,
      exchangingData: {
        RO_NO: this.getdata.RO_NO,
        ASC_SHORTNAME: this.getdata.ASC_SHORTNAME,
        projectName: '',
        assignLabourHour: '',
        troubleDesc: ''
      }
    };
  },
  mounted() {
    this.queryChargeList();
    this.querySeries();
    this.queryRepairItem();
    this.serviceConsultant();
    // this.getSflbList();
  },
  methods: {
    createTable1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filter: true,
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter: true,
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '故障原因',
          dataIndex: 'TROUBLE_CAUSE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '项目代码',
          dataIndex: 'LABOUR_CODEF',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修项目名称',
          dataIndex: 'LABOUR_NAME',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '组合代码',
          dataIndex: 'PACKAGE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'MODEL_LABOUR_CODE',
          sorter: true,
          filter: true,
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '标准工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },

        {
          title: '索赔工时',
          dataIndex: 'CLAIM_LABOUR',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },

        {
          title: '工种',
          dataIndex: 'WORKER_TYPE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.WORKER_TYPE_CODE, '8041')}</span>;
          }
        },
        {
          title: '是否派工',
          dataIndex: 'ASSIGN_TAG',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.CONSIGN_EXTERIOR, '1004')}</span>;
          }
        },
        {
          title: '是否委外',
          dataIndex: 'CONSIGN_EXTERIOR',
          sorter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.CONSIGN_EXTERIOR, '1004')}</span>;
          }
        },
        {
          title: '是否不修',
          dataIndex: 'NEEDLESS_REPAIR',
          sorter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.NEEDLESS_REPAIR, '1004')}</span>;
          }
        },
        {
          title: '责任技师',
          dataIndex: 'TECHNICIAN',
          sorter: true,
          filter: true,
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '是否预检',
          dataIndex: 'PRE_CHECK',
          sorter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.PRE_CHECK, '1004')}</span>;
          }
        },
        {
          title: '是否内返',
          dataIndex: 'INTER_RETURN',
          sorter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.INTER_RETURN, '1004')}</span>;
          }
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '合同编号',
          dataIndex: 'SSP_CONTRACT_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '检查结果',
          dataIndex: 'TROUBLE_DESC',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: false,
          editType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          minWidth: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
      ];
    },
    closepop(val) {
      this.exchangingVisible = false;
    },
    // 查询收费区分
    async queryChargeList() {
      const res = await queryChargeDifferentiationList();
      // console.log(res, 'res');
      this.columns1.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').editItems = res.data.map(x => ({
        value: x.CHARGE_PARTITION_CODE + '',
        text: x.CHARGE_PARTITION_NAME
      }));
    },

    // 查询所有车系(供table使用)
    async querySeries() {
      const res = await getSeries();
      console.log(res.data, 'lmmmmmmmmmmmmmm');
      this.columns1.find(x => x.dataIndex === 'MODEL_LABOUR_CODE').editItems = res.data.map(x => ({ text: x.SERIES_NAME, value: x.SERIES_ID + '' }));
    },

    // 查询维修项目
    async queryRepairItem() {
      const roNo = this.roNo;
      const res = (await queryRepairLabour(roNo)).data.rows;
      this.list = res;
    },

    // 获取维修项目类型
    // async getWxtypeSelect() {
    //   const res = await getWxlxSelect();
    //   this.columns.find(x => x.dataIndex === 'REPAIR_TYPE_NAME').editItems = res.data.map(x => ({
    //     value: x.REPAIR_TYPE_CODE + '',
    //     text: x.REPAIR_TYPE_NAME
    //   }));
    // },

    // 售前人员接口数据
    async serviceConsultant() {
      // let consultant = { role: dictCode.SERVICE_CONSULTANT }; // 服务顾问
      let technician = { role: dictCode.TECHNICIAN }; // 指定技师
      // const consultantRes = await searchRoleByCode(consultant);
      const technicianRes = await searchRoleByCodes(technician);
      // this.topFilterList.find(x => x.fieldName === 'serviceAdvisor').itemList = consultantRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns1.find(x => x.dataIndex === 'TECHNICIAN').editItems = technicianRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
    }
  }
};
</script>
